import type {
  centerTaskByCodeResponse,
  ChartData,
  CountryQhInfo,
  DataListResponse,
  HotTaskTop5DetailItem,
  HotTop5DetailItem,
  HotTop5Item,
  levelOne,
  OneMachineCountryResponse,
  PositionAndDateArray,
  TaskByShenpilbResponse,
  TaskNumResponse,
  windowWaitResponse,
  windowWaitSingleResponse,
  ytjDetail
} from '@/types/baseTypes'
import Request from './axios-request'

class baseAxios {
  public axios: Request

  constructor() {
    this.axios = new Request({ url: import.meta.env.VITE_API_BASE_URL_API })
  }

  public post(url: string, data?: object) {
    return this.axios.post(url, data)
  }

  public get(url: string, data?: object) {
    return this.axios.get(url, data)
  }

  public GetNearlyHalf(): Promise<ChartData[]> {
    return this.axios.get(`/getNearlyHalf`)
  }

  public GetPositionAndDate(params: {
    params: {
      type: '0' | '1'
    }
  }): Promise<PositionAndDateArray[]> {
    return this.axios.post(`/getPositionAndDate`, params)
  }

  public GetOneMachineCountry(): Promise<OneMachineCountryResponse> {
    return this.axios.get(`/getOneMachineCountry`)
  }

  public GetNearlyBjl(): Promise<DataListResponse[]> {
    return this.axios.get(`/getNearlyBjl`)
  }

  public GetTaskNum(): Promise<TaskNumResponse> {
    return this.axios.get(`/getTaskNum`)
  }

  public GetTaskByShenpilb(shenpilb: string): Promise<TaskByShenpilbResponse> {
    return this.axios.post(`/getTaskByShenpilb`, { shenpilb })
  }

  public GetCountryQhInfo(): Promise<CountryQhInfo> {
    return this.axios.get(`/getCountryQhInfo`)
  }

  public GetWjzjHotTop5(): Promise<HotTop5Item[]> {
    return this.axios.post(`/getWjzjHotTop5`, { token: `Epoint_WebSerivce_**##0601`, params: {} })
  }

  public GetWjzjHotTop5Detail(params: {
    taskguid: string
    first: number
    pageSize: number
  }): Promise<{
    code: number
    datacount: number
    datalist: HotTop5DetailItem[]
    text: string
  }> {
    return this.axios.post(`/getWjzjHotTop5Detail`, {
      token: `Epoint_WebSerivce_**##0601`,
      params
    })
  }

  public GetHotTaskTop5(): Promise<HotTop5Item[]> {
    return this.axios.post(`/getHotTaskTop5`, { token: `Epoint_WebSerivce_**##0601`, params: {} })
  }

  public GetHotTaskTop5Detail(params: {
    taskguid: string
    first: number
    pageSize: number
  }): Promise<{
    code: number
    datacount: number
    datalist: HotTop5DetailItem[] | HotTaskTop5DetailItem[]
    text: string
  }> {
    return this.axios.post(`/getHotTaskTop5Detail`, {
      token: `Epoint_WebSerivce_**##0601`,
      params
    })
  }

  public GetXzxkPercent(): Promise<{ percent: string; shenpilb: string }[]> {
    return this.axios.get(`/getXzxkPercent`)
  }

  public GetCangoRegionList(params: {
    code: string
    level: number
  }): Promise<{ code: string; name: string }[]> {
    return this.axios.post(`/getCangoRegionList`, params)
  }

  public GetTaskAndCount(params: { startDate: string; endDate: string }): Promise<levelOne[]> {
    return this.axios.post(`/getTaskAndCount`, params)
  }

  public GetCountLegalPersonData(year: string): Promise<
    {
      codeType: string
      establishDate: string
      totalRegCapital: string
      totalLegalPerson: string
    }[]
  > {
    return this.axios.get(`/getCountLegalPersonData?year=${year}`)
  }

  public GetYtjcount(params: {
    params: {
      order: 'asc' | 'desc'
    }
  }): Promise<ytjDetail[]> {
    return this.axios.post(`/getYtjcount`, params)
  }

  public GetYtjcountTown(params: {
    params: {
      type: 'town'
      order: 'asc' | 'desc'
    }
  }): Promise<
    {
      townname: string
      ytjlist: ytjDetail[]
    }[]
  > {
    return this.axios.post(`/getYtjcountTown`, params)
  }

  public GetCenterTaskTypeQhCountByAreaCode(params: {
    areacode: string
  }): Promise<centerTaskByCodeResponse[]> {
    return this.axios.post(`/getCenterTaskTypeQhCountByAreaCode`, params)
  }

  public GetzqinfoList(params: {
    token: `Epoint_WebSerivce_**##0601`
    params: {
      centerguid: string
    }
  }): Promise<windowWaitResponse[]> {
    return this.axios.post(`/getzqinfoList`, params)
  }

  public GetzqList(params: {
    token: `Epoint_WebSerivce_**##0601`
    params: {
      zqrowguid: string // 来自接口2.13出参 专区唯一标识
      pageindex: number // 页码
      pagesize: number // 页距
    }
  }): Promise<windowWaitSingleResponse> {
    return this.axios.post(`/getzqList`, params)
  }
}
export default new baseAxios()
